<!--
 * Copyright © 2022 XXXXXXXXX
 * @Author: zhangxiang
 * @Date: 2022-09-14 15:29:24
 * @LastEditors: zhangxiang
 * @LastEditTime: 2022-11-03 09:57:51
 * @Description:
 *
-->

<template>
  <div ref="eventCtn" class="event-top10-ctn">
    <div v-for="(items, index) in top10Divide" :key="index" class="column">
      <div v-if="index > 0" class="line"></div>
      <div class="items">
        <div v-for="(item, idx) in items" :key="idx" class="item">
          <img
            alt=""
            src="@/assets/imgs/statis-analysis/icon_top10_default.png"
            class="icon"
          />
          <div class="content">
            <span class="num">{{ item.num }}</span>
            <el-tooltip effect="dark" :content="item.reason" placement="top">
              <span class="reason" :style="{ width: reasonWidth + 'px' }">{{
                item.reason
              }}</span>
            </el-tooltip>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'EventTop10',
  props: {
    // 数据
    top10: {
      type: Array, // 类型
      required: true, // 必须
      default: () => [] // 默认值
    }
  },
  data() {
    return {
      reasonWidth: 160 // 事件名称视图宽度
    }
  },
  computed: {
    /**
     *
     * @description: 两个一行按行分割数据
     * @return {*}
     *
     */
    top10Divide() {
      const arr = []
      let index = 0
      while (index < this.top10.length) {
        // 循环
        arr.push(this.top10.slice(index, (index += 2))) // 两两一行
      }
      return arr
    }
  },
  mounted() {
    this.reasonWidth = (this.$refs.eventCtn.clientWidth * 0.8 - 42) / 2 - 46 // 动态计算宽度
  }
}
</script>

<style lang="less" scoped>
@import "@/assets/css/common.less";
.event-top10-ctn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  .column {
    width: 100%;
    padding: 0 10%;
    box-sizing: border-box;

    .line {
      height: 1px;
      background-color: #f2f2f2;
      margin: 3% 0;
    }

    .items {
      display: flex;
      align-items: center;

      .item {
        flex: 1;
        display: flex;
        align-items: center;
        margin-left: 12px;
        flex-shrink: 0;
        overflow: hidden;

        &:last-child {
          margin-left: 30px;
        }

        .icon {
          width: 36px;
          height: 36px;
          margin-right: 10px;
        }

        .content {
          display: flex;
          flex-direction: column;
          align-items: flex-start;

          .num {
            .textStyle(24px, 900, #4a4a4a);
            line-height: 33px;
          }

          .reason {
            .textStyle(14px, 500, #C3C3C3);
            line-height: 20px;
            text-align: left;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }
  }
}
</style>
